package com.ruoyi.workFlow.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity;
import org.activiti.api.task.model.Task;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;

import java.util.Date;
import java.util.Map;

public class ActTaskDTO extends BaseEntity {

    private static final long serialVersionUID = 1L;

    private String id;

    private String name;

    private String status;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createdDate;
    private String instanceName;
    private String definitionKey;
    private String businessKey;

    //创建者
    private String createName;
    //订单编号
    private String orderCode;
    //单据类型
    private Integer processType;
    private Map<String,Object> variables;
    public ActTaskDTO() {
    }

    public ActTaskDTO(Map<String,Object> variables, Task task, ProcessInstance processInstance) {
        this.variables = variables;
        this.createName = null == variables.get("createName") ? "" : variables.get("createName").toString();
        this.processType = null == variables.get("processType") ? 1 : Integer.parseInt(variables.get("processType").toString());
        this.orderCode = null == variables.get("orderCode") ? "" : variables.get("orderCode").toString();
        this.id = task.getId();
        this.name = task.getName();
        this.status = task.getStatus().toString();
        this.createdDate = processInstance.getStartTime();
        this.instanceName = processInstance.getProcessDefinitionName();
        this.definitionKey=processInstance.getProcessDefinitionKey();
        this.businessKey=processInstance.getBusinessKey();
    }

    public ActTaskDTO(HistoricProcessInstance historicProcessInstance, ProcessInstance processInstance) {
        this.id = historicProcessInstance.getId();
        this.instanceName = processInstance.getProcessDefinitionName();
        this.status = "审核中";
        this.createdDate = historicProcessInstance.getStartTime();
        this.name = processInstance.getName();
        this.definitionKey=processInstance.getProcessDefinitionKey();
        this.businessKey=processInstance.getBusinessKey();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getStatus() {
        return "待审核";
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getInstanceName() {
        return instanceName;
    }

    public void setInstanceName(String instanceName) {
        this.instanceName = instanceName;
    }

    public String getDefinitionKey() {
        return definitionKey;
    }

    public void setDefinitionKey(String definitionKey) {
        this.definitionKey = definitionKey;
    }

    public String getBusinessKey() {
        return businessKey;
    }

    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }

    public Map<String, Object> getVariables() {
        return variables;
    }

    public void setVariables(Map<String, Object> variables) {
        this.variables = variables;
    }

    public String getCreateName() {
        return createName;
    }

    public void setCreateName(String createName) {
        this.createName = createName;
    }

    public String getOrderCode() {
        return orderCode;
    }

    public void setOrderCode(String orderCode) {
        this.orderCode = orderCode;
    }

    public Integer getProcessType() {
        return processType;
    }

    public void setProcessType(Integer processType) {
        this.processType = processType;
    }
}
